n, m, k = map(int, input().split())
h = []
for i in range(n):
h.append(list(map(int, input().split())))
v = []
for i in range(n - 1):
v.append(list(map(int, input().split())))
if k % 2 == 0:
d = [[0] * m for i in range(n)]
for t in range(k // 2):
dt = [[0] * m for i in range(n)]
for i in range(n):
for j in range(m):
x = float('inf')
if i - 1 >= 0:
x = min(x, d[i - 1][j] + v[i - 1][j] * 2)
if i + 1 < n:
x = min(x, d[i + 1][j] + v[i][j] * 2)
if j - 1 >= 0:
x = min(x, d[i][j - 1] + h[i][j - 1] * 2)
if j + 1 < m:
x = min(x, d[i][j + 1] + h[i][j] * 2)
dt[i][j] = x
d = dt.copy()
else:
d = [[-1] * m for i in range(n)]
for i in d:
print(*i)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
vector <vector <int>> h(n, vector <int> (m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m - 1; ++j) {
cin >> h[i][j];
}
}
vector <vector <int>> v(n, vector <int> (m));
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < m; ++j) {
cin >> v[i][j];
}
}
if (k & 1) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cout << -1 << " \n"[j + 1 == m];
}
}
}
else {
vector <vector <vector<ll>>> dist(n,
vector <vector <ll>> (m,
vector <ll> ((k >> 1) + 1, INT_MAX)));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
dist[i][j][0] = 0;
}
}
for (int kk = 1; kk <= k / 2; ++kk) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i > 0) {
dist[i][j][kk] = min(dist[i][j][kk], dist[i - 1][j][kk - 1] + v[i - 1][j]);
}
if (j > 0) {
dist[i][j][kk] = min(dist[i][j][kk], dist[i][j - 1][kk - 1] + h[i][j - 1]);
}
if (i < n - 1) {
dist[i][j][kk] = min(dist[i][j][kk], dist[i + 1][j][kk - 1] + v[i + 0][j]);
}
if (j < m - 1) {
dist[i][j][kk] = min(dist[i][j][kk], dist[i][j + 1][kk - 1] + h[i][j + 0]);
}
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cout << 2 * dist[i][j][k / 2] << " \n"[j + 1 == m];
}
}
}
}
1553D - Backspace | 1670D - Very Suspicious |
1141B - Maximal Continuous Rest | 1341A - Nastya and Rice |
1133A - Middle of the Contest | 385A - Bear and Raspberry |
1311B - WeirdSort | 1713F - Lost Array |
236B - Easy Number Challenge | 275A - Lights Out |
147A - Punctuation | 253A - Boys and Girls |
1327E - Count The Blocks | 984A - Game |
12B - Correct Solution | 1355B - Young Explorers |
485A - Factory | 628A - Tennis Tournament |
1436B - Prime Square | 1707B - Difference Array |
1422C - Bargain | 1611F - ATM and Students |
660A - Co-prime Array | 1692F - 3SUM |
1470A - Strange Birthday Party | 190D - Non-Secret Cypher |
1721B - Deadly Laser | 1721C - Min-Max Array Transformation |
1721A - Image | 1180C - Valeriy and Deque |